


import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 佳宝商品相关接口
 *
 * allen  2023-12-19
 */

/**
 * 
 * 获取商品详情
 * id：商品id, type:暂时不知道是啥
 */
const queryProductDetail = (id, type = '') => {
  return new Promise((resolve, reject) => {
    get("/api/front/product/detail/" + id + "?type=" + type).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 
 * 获取秒杀商品详情
 * id：商品id,
 */
const querySeckillProductDetail = (id) => {
  return new Promise((resolve, reject) => {
    get("/api/front/seckill/detail/" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
* 
* 商品详情下面的优品推荐
* 
*/
const queryProducGood = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/product/good").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}



/**
 * 
 * 获取商品评价
 * id：商品id, type:0:全部，1：好评，2：中评，3：差评
 */
const queryProductReply = (id, page, limit, type) => {
  return new Promise((resolve, reject) => {
    get("/api/front/reply/list/" + id + "&page=" + page + "&limit=" + limit + "&type=" + type).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 分类商品获取
 * params:{
 *   keyword,
 *   priceOrder,
  * salesOrder,
  * news,
  * page,
  * limit,
  * cid
 * }
 */
const queryCategoryProductList = (params) => {
  return new Promise((resolve, reject) => {
    get("/api/front/products", params).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 *
 * 商品评价信息
 *  productId
 * }
 */
const queryProductReplyInfo = (productId) => {
  return new Promise((resolve, reject) => {
    get("/api/front/reply/product/" + productId).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 *
 * 商品评价数量
 *  productId
 * }
 */
const queryProductReplyNumbers = (productId) => {
  return new Promise((resolve, reject) => {
    get("/api/front/reply/config/" + productId).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 *
 * 商品评价列表
 *  productId
 * }
 */
const queryProductReplyList = (productId, page, limit, type) => {
  return new Promise((resolve, reject) => {
    get("/api/front/reply/list/" + productId + "?page=" + page + "&limit=" + limit + "&type=" + type).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}






module.exports = {
  queryProductDetail,
  queryProducGood,//商品详情下面的优品推荐
  queryProductReply,
  queryCategoryProductList,
  querySeckillProductDetail,
  queryProductReplyInfo,
  queryProductReplyNumbers,
  queryProductReplyList
}

